package haha.life.common;

import haha.life.normal.CommonConvertUtils;
import haha.life.normal.FileUtil;
import jzqb.bo.DBBo;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 系统工具类
 */

public class SysTool {
    /*---------------zzp-------------------------*/
    public static final int LIMIITNUM = 100;
    /*---------------cw-------------------------*/
    //情报百科_退审组
    public static final String QBFW_TuiShenZu = "95";
    //情报百科_审核组
    public static final String QBBK_ShenHeZu = "96";
    //情报服务_资源审批组
    public static final String QBFW_ZiYuanShenPiZu = "97";
    //情报百科_权限审批组
    public static final String QBFW_QuanXianShenPiZu = "98";
    //是否展示自用库的按钮
    public static final String QBFW_SelfBaseButton = "83";
    /*---------------xtt-------------------------*/

    /*---------------cy-------------------------*/
    public static final String dateFormat_milli = "yyyy-MM-dd HH:mm:ss";

    public static final String dateFormat_date = "yyyy-MM-dd";

    //处理时间格式 往左   2021-10-10  ->  2021-10-10 00:00:00
    public static final String left = "left";
    //处理时间格式 往右  2021-10-10   ->  2021-10-10 23:59:59
    public static final String right = "right";
    //通知公告表_目标部门字段  getBelongTo
    public static final String YQTTZGG_TargetDept = "目标部门";

    //动态新闻表名
    public static final String YQTDTXW = "YQTDTXW";
    //情报百科全局id
    public static final String QBBK_SYSID = "SYS_FLD_SYSID";
    //文件存放的  文件夹名
    public static final String pagesTypes = "Pages";
    //封面存放的  文件夹名
    public static final String imageTypes = "Images";

    //情报资源表名
    public static String QBZS_METADATA = "JZQBZS_METADATA";
    //情报成果表名
    public static String QBCG_METADATA = "JZCG_METADATA";
    //情报自用表名
    public static String QBZY_METADATA = "JZZY_METADATA";
    //情报百科表名
    public static String QBBK_METADATA = "JZQBBK_METADATA";
    //情报百科模板表表名
    public static final String YQTQBBKMB = "YQTQBBKMB";
    //
    public static final String JZBASE_METADATA = "JZBASE_METADATA";
    public static final String templateRepeat = "模板名重复";
    //专题集表名
    public static String ZTJ_METADATA = "YQTZTJ_METADATA";
    //专题表名
    public static String ZT_METADATA = "YQTZT_METADATA";
    //专题文献表名
    public static String ZTWX_METADATA = "YQTZTWX_METADATA";

    //九洲影音表名
    public static String JSYY_METADATA = "JZJSYY_METADATA";

    //部门表-情报部门id
    public static final String YQTBMB_QBID = "businessDepartment";

    //情报资源
    public static final String QBZYUAN = "QBZYUAN";
    //研究成果
    public static final String YJCG = "YJCG";
    //情报自用
    public static final String QBZY = "QBZY";
    //百科词条
    public static final String BKCT = "BKCT";
    //CNKI报纸
    public static final String BZ = "BZ";
    //CNKI博士论文
    public static final String BSLW = "BSLW";
    //CNKI期刊
    public static final String QK = "QK";
    //CNKI硕士论文
    public static final String SSLW = "SSLW";
    //CNKI中国会议
    public static final String ZGHY = "ZGHY";
    //CNKI国际会议
    public static final String GJHY = "GJHY";
    //专题文献
    public static final String ZTWX = "ZTWX";
    //会议视频
    public static final String HYSP = "HYSP";

    //八大领域
    public static final String SB = "SB";

    //八大领域
    public static final String TX = "TX";

    //八大领域
    public static final String SP = "SP";

    //八大领域
    public static final String KG = "KG";

    //八大领域
    public static final String TC = "TC";

    //八大领域
    public static final String FK = "FK";

    //八大领域
    public static final String DZ = "DZ";

    //八大领域
    public static final String QT = "QT";


    /*-----------------油气田-------------------------*/
    public static final String NODATAMESSAGE="未查询到数据";

    /*---------------method-------------------------*/

    /**
     * 时间格式处理 添加到毫秒
     *
     * @param time
     * @param key
     * @return
     */
    public static String dealTime(String time, String key) {
        String returnTime = time;
        if ("".equals(time) || time == null) {
            return returnTime;
        }
        if ("left".equals(key)) {
            returnTime += " 00:00:00";
        } else if ("right".equals(key)) {
            returnTime += " 23:59:59";
        }
        return returnTime;
    }

    /**
     * 获取当前时间
     *
     * @param format 时间格式
     * @return
     */
    public static String getCurrentTime(String format) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat(format);
        String time = simpleDateFormat.format(new Date());
        return time;
    }


    /**
     * 通过Key 获得DBBO 对象
     *
     * @param Key
     * @return
     */
    public static DBBo getDBBoByKey(String Key) {
        String jsonResult = FileUtil.readJsonFile("db.json");
        List<DBBo> dbBoList = CommonConvertUtils.getJsonToList(jsonResult, DBBo.class);
        for (DBBo dbBo : dbBoList) {
            if (dbBo.getKey().equals(Key)) {
                return dbBo;
            }
        }
        return null;
    }

    /**
     * 读取配置文件然后获取文件名称
     * JZQBBK_METADATA,JZQBZS_METADATA,JZCG_METADATA,YQTZTWX_METADATA,CCNDLAST2019_06,CDFDLAST2019_06,CJFDLAST2019_06,CMFDLAST2019_06,CPFDLAST2019_06,IPFDLAST2019_06
     *
     * @param
     * @return
     */
    public static String getTableNameByDBJSON() {
        String jsonResult = FileUtil.readJsonFile("db.json");
        List<DBBo> dbBoList = CommonConvertUtils.getJsonToList(jsonResult, DBBo.class);
        StringBuffer stringBuffer = new StringBuffer();
        for (DBBo dbBo : dbBoList) {
            stringBuffer.append(dbBo.getDbCode()).append(",");
        }
        return stringBuffer.substring(0,stringBuffer.length() - 1);
    }
}


